﻿Namespace Control
    Public Class EstoqueLocal
        Implements IControl(Of Model.EstoqueLocal)
        Implements IDisposable

        Public Function Excluir(entity As Model.EstoqueLocal) As Boolean Implements IControl(Of Model.EstoqueLocal).Excluir
            Dim Result As Boolean = True

            Try
                entity.Delete()
            Catch ex As Exception
                Dialog.Alert(ex.Message)
                Result = False
            End Try

            Return Result
        End Function

        Public Function ListaTudo() As IList(Of Model.EstoqueLocal) Implements IControl(Of Model.EstoqueLocal).ListaTudo
            Return Model.EstoqueLocal.FindAll()
        End Function

        ''' <summary>
        ''' Pesquisa por descrição
        ''' </summary>
        ''' <param name="Descricao">Texto a ser pesquisado</param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Function ListaByDescricao(Optional ByVal Descricao As String = "") As IList(Of Model.EstoqueLocal)
            Dim estoqueLocal As New Model.EstoqueLocal

            If Not String.IsNullOrEmpty(Descricao) Then
                Return estoqueLocal.GetByDescricao(Descricao)
            Else
                Return Model.EstoqueLocal.FindAll()
            End If

        End Function

        Public Function ListaUm(entity As Model.EstoqueLocal) As Model.EstoqueLocal Implements IControl(Of Model.EstoqueLocal).ListaUm
            Return Model.EstoqueLocal.Find(entity.cd_estoque_local)
        End Function

        Public Function Salvar(entity As Model.EstoqueLocal) As Boolean Implements IControl(Of Model.EstoqueLocal).Salvar
            entity.Save()
        End Function

        Public Function GetById(ByVal id As Integer) As Model.EstoqueLocal
            Return Model.EstoqueLocal.Find(id)
        End Function

#Region "IDisposable Support"
        Private disposedValue As Boolean ' To detect redundant calls

        ' IDisposable
        Protected Overridable Sub Dispose(disposing As Boolean)
            If Not Me.disposedValue Then
                If disposing Then
                    ' TODO: dispose managed state (managed objects).
                End If

                ' TODO: free unmanaged resources (unmanaged objects) and override Finalize() below.
                ' TODO: set large fields to null.
            End If
            Me.disposedValue = True
        End Sub

        ' TODO: override Finalize() only if Dispose(ByVal disposing As Boolean) above has code to free unmanaged resources.
        'Protected Overrides Sub Finalize()
        '    ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
        '    Dispose(False)
        '    MyBase.Finalize()
        'End Sub

        ' This code added by Visual Basic to correctly implement the disposable pattern.
        Public Sub Dispose() Implements IDisposable.Dispose
            ' Do not change this code.  Put cleanup code in Dispose(disposing As Boolean) above.
            Dispose(True)
            GC.SuppressFinalize(Me)
        End Sub
#End Region

    End Class
End Namespace

